// ActionScript file
import com.xsky.dataGrid.DataProxy;
import com.xsky.web.WebSrv;

/* import component.CheckBoxItemRender; */

import mx.controls.dataGridClasses.DataGridColumn;
import mx.core.ClassFactory;

public function initGridInfo():void
{
	genDataGridInfo();
}
public function resetPageInfo(numbers:Number):void
{
	totalNumbers = numbers;
/* 	totalPages = Math.ceil(totalNumbers/Number(numberPerPageComboBox.text)); */
	if(recentPage==0)
	{
		recentPage=1;
	}
	
}
public function nextPage():void //请求下一页数据
{
	if (recentPage + 1 > totalPages)
	{
		mx.controls.Alert.show("当前已经是最后一页");
		return;
	}
	else
	{
		recentPage = recentPage  + 1;
	}
	search();
}

public function prePage():void //请求上一页数据
{
	if (recentPage  - 1 < 1)
	{
		mx.controls.Alert.show("当前已经是第一页");
		return;
	}
	else
	{
		recentPage =recentPage  - 1;
	}
	search();
}

public function lastPage():void //请求最后一页数据
{
	if (recentPage== totalPages)
	{
		return;
	}
	else
	{
		recentPage=totalPages;
	}
	search();
}

public function firstPage():void //请求第一页数据
{
	if (recentPage - 1 < 1)
	{
		return;
	}
	else
	{
		recentPage=1;
	}
	search();
}

public function goPage():void //跳转到第几页
{
/* 	if (Number(toPage.text) < 1)
	{
		recentPage=1;
	}
	else if (Number(toPage.text) > totalPages)
	{
		toPage.text = totalPages.toString();
		recentPage=totalPages;
	}
	else
	{
		recentPage=Number(toPage.text);
	}
	search(); */
}
/*初始化数据表*/
public function genDataGridInfo():void
{
	/* var webSrv:WebSrv = new WebSrv(params["gridService"]);
	var paramObj:Object=new Object();
	paramObj["in0"]=params["tableName"];
	webSrv.invokeWebSrv("genGridTemplate", paramObj);
	webSrv.onComplete=function(result:String):void
	{
		var gridTemplate:XML = new XML(result);
		var searchTemplate:XML = new XML(gridTemplate.search.toString());//检索的模板
		var columnTemplate:XML = new XML(gridTemplate.columns.toString());//数据列的模板
		var toolsTemplate:XML = new XML(gridTemplate.tools.toString()); //工具模板
		var styleTemplate:XML = new XML(gridTemplate.style.toString());//
		var userProxy:String = gridTemplate.@proxy;
		params["userProxy"]=userProxy;
		params["gridTemplate"]=gridTemplate;
		params["searchTemplate"]=searchTemplate;
		params["columnTemplate"]=columnTemplate;
		params["toolsTemplate"]=toolsTemplate;
		params["styleTemplate"]=styleTemplate;
		initDataGrid(gridTemplate);
	    internationalization(styleTemplate);
	    initTools(toolsTemplate);
	    createSearchPanel(searchTemplate);
	    createAddPanel(columnTemplate); */
	    
	}
		/* dataGrid.columns = new Array();	
		params["addFormValidator"]=new Array();
		params["searchFormValidator"]=new Array();
		gridTemplate=params["template"];
		this.pageName = params["pageName"];
		this.tableName=params["tableName"];
		this.condition=mx.core.Application.application.condition;
		var tableEditable:String = gridTemplate.@editable;
		var btnUploadEnable:String = gridTemplate.@uploadable;
		var btnDownloadEnable:String = gridTemplate.@downloadable;
		
		if(tableEditable=="F")
		{
			dataGrid.editable = false;
			btnAdd.visible = false;
			btnUpdate.visible = false;
			btnDelete.visible = false;
		}
		else
		{
			var checkBoxCloumn:DataGridColumn = new DataGridColumn();
			checkBoxCloumn.itemRenderer = new ClassFactory(component.common.CheckBoxItemRender);
			dataGrid.columns=dataGrid.columns.concat(checkBoxCloumn);
			checkBoxCloumn.editable = false;
			checkBoxCloumn.sortable = false;
		}
		createSearchPanel(gridTemplate);
		if(btnUploadEnable!=null)
		{
			if(btnUploadEnable=="F")
			{
				btnUpload.visible = false;
			}
		}
		if(btnDownloadEnable!=null)
		{
			if(btnDownloadEnable=="F")
			{
				btnDownload.visible = false;
			}
		}
		for each (var item:XML in gridTemplate.column)
		{
			var dataGridColumn:DataGridColumn=new DataGridColumn();
			dataGridColumn.dataField=item.@name;
			dataGridColumn.setStyle("headerStyleName", "centered");
			dataGridColumn.headerText=item.@label;
			if (item.@visible == "F")
			{
				dataGridColumn.visible=false;
			}
			else
			{

			}
			if(item.@editable=="F")
			{
				dataGridColumn.editable = false;
			}
			else
			{
				
			}
			dataGrid.columns=dataGrid.columns.concat(dataGridColumn); 
			//dataGrid.columns.push(dataGridColumn); 
		}
		createAddPanel(gridTemplate);
		addRecordPanel.initApp(validatorArr);
		httpExportService.addEventListener(ResultEvent.RESULT,callbackExport);
		httpService.addEventListener(ResultEvent.RESULT,callbackQuery);
		 queryData();  */
/* } */
//初始化数据表
public function initDataGrid(dataGridTemplate:XML):void
{
	/* var columnsArray:Array = new Array();
	var columnTemplate:XML = params["columnTemplate"];
	var tableEditable:String = dataGridTemplate.@editable;
	var titleStr:String = dataGridTemplate.@title;
	dataGridTitle.text = titleStr;
	if(tableEditable=="F")
	{
		dataGrid.editable = false;
	}
	else
	{
		var checkBoxCloumn:DataGridColumn = new DataGridColumn();
		checkBoxCloumn.width=25;
		checkBoxCloumn.itemRenderer = new ClassFactory(component.CheckBoxItemRender);
		checkBoxCloumn.editable = false;
		checkBoxCloumn.sortable = false;
		columnsArray.push(checkBoxCloumn);
		dataGrid.columns=dataGrid.columns.concat(checkBoxCloumn);
	}
	for each (var item:XML in columnTemplate.column)
	{
		
		var dataGridColumn:DataGridColumn=new DataGridColumn();
		dataGridColumn.dataField=item.@name;
		dataGridColumn.setStyle("headerStyleName", "centered");
		dataGridColumn.headerText=item.@label;
		if (item.@visible == "F")
		{
			dataGridColumn.visible=false;
		}
		else
		{

		}
		if(item.@editable=="F")
		{
			dataGridColumn.editable = false;
		}
		else
		{
			
		}
		columnsArray.push(dataGridColumn);
	}
	dataGrid.columns = columnsArray;
	initPageNumbers(); */
}
public function initPageNumbers():void
{
	/* var webSrvice:WebSrv = new WebSrv(params["gridService"]);
	trace(params["gridService"]);
	var paramObj:Object=new Object();
	paramObj["in0"]="pageNumber";
	webSrvice.invokeWebSrv("genConfig", paramObj);
	webSrvice.onComplete=function(result:String):void
	{
		trace("numbers========================="+result);
		 var numberXml:XML = new XML(result);
		numberPerPageComboBox.dataProvider = numberXml.item; 
		search(); 
	}*/
}
public function showItemInfo():void
{
	/* var selectedItemStr:String = dataGrid.selectedItem[0].toString();
	var tableName:String = params["tableName"];
	var dataProxy:DataProxy = new DataProxy();
	dataProxy.showItemInfo(tableName,new XML(selectedItemStr),this); */
}
public function internationalization(styleTemplate:XML):void
{
/* 	pageInfo1.text = styleTemplate.pageInfo1;
	pageInfo2.text = styleTemplate.pageInfo2;
	pageInfo3.text = styleTemplate.pageInfo3;
	pageInfo4.text = styleTemplate.pageInfo4;
	pageInfo5.text = styleTemplate.pageInfo5;
	pageInfo6.text = styleTemplate.pageInfo6;
	pageInfo7.text = styleTemplate.pageInfo7;
	pageInfo8.text = styleTemplate.pageInfo8;
	btnFirstPage.label = styleTemplate.btnFirstPage;
	btnPrePage.label = styleTemplate.btnPrePage;
	btnNextPage.label = styleTemplate.btnNextPage;
	btnLastPage.label = styleTemplate.btnLastPage; */
}
